package com.javaweb.common;

import java.io.Serializable;
import java.util.Map;

/**
 * Value Object for passing response from methods in service level.
 */
public class ServiceResponse implements Serializable  {
    public static int SUCCESS = 0 ;
    public static int ERROR = -1 ;

    private int status ;
    private String msg ;
    private Map<String, Object> data ;

    public ServiceResponse() {}

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public boolean isSucceed() {
        return this.status == SUCCESS ;
    }

    public static ServiceResponse successResp(String msg) {
        ServiceResponse resp = new ServiceResponse() ;
        resp.setStatus(SUCCESS);
        resp.setMsg(msg);
        return resp ;
    }
    public static ServiceResponse errorResp(String msg) {
        ServiceResponse resp = new ServiceResponse() ;
        resp.setStatus(ERROR);
        resp.setMsg(msg);
        return resp ;
    }





}
